package com.sinovatio.dbserver.common;


import java.util.HashMap;
import java.util.Map;

public class ResultCode {

    private static Map<Integer, String> codeMap = new HashMap<>();
    
    public static final int SUCCESS = 200;
    static final int BAD_REQUEST = 400;
    static final int DATA_NOT_EXISTS = 404;
    static final int SYSTEM_ERROR = 500;


    private static final int UNKNOWN_ERROR = -99;

    static {
        registerCode(SUCCESS, "请求成功");
        registerCode(BAD_REQUEST, "客户端错误");
        registerCode(DATA_NOT_EXISTS, "数据不存在");
        registerCode(SYSTEM_ERROR, "系统错误");
        registerCode(UNKNOWN_ERROR, "未知错误");

    }

    public static void registerCode(int code, String message) {
        codeMap.put(code, message);
    }

    public static String getMessage(int code) {
        if (codeMap.containsKey(code)) {
            return codeMap.get(code);
        } else {
            return codeMap.get(UNKNOWN_ERROR);
        }
    }
}

